<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title> 
    <style>
        .right {
            color: green;
        }
        .error {
            color: red;
        }
    </style>
</head>
<body>
    <input type="password">
    <span></span>

    <script>
        const input = document.querySelector('input');
        const span = document.querySelector('span');
        input.addEventListener('blur',()=>{ // 焦点离开事件
            const len = input.value.trim().length;
            if(len >= 6 && len <= 16){
                // right
                span.innerHTML = '您输入正确';
                span.className = 'right';
            }else{
                // error
                span.innerHTML = '请输入6 - 16位长度';
                span.className = 'error';
            }
        });
    </script>

</body>
</html>